/*
DIRLIST
*/

#include <plib.h>
#include <prndir.g>

#pragma METHOD_CALL

METHOD INT dirlist_va_test(PR_DIRLIST *self,RC_VAXVAR *prec1,RC_VAXVAR *prec2)
/*
Firstly perform a 2 way test on file or dir name records.
Order dir names before file names.
Otherwise order names alphabetically.
Return 0 if equal, <0 if *prec1 is before *prec2, >0 if after.
*/
    {
    FAST DIRLIST_ITEM *p1,*p2;
    FAST INT ret;

    ret=0;
    p1=(DIRLIST_ITEM *)prec1->buf;
    p2=(DIRLIST_ITEM *)prec2->buf;
    if ((p1->info.status&P_FADIR)^(p2->info.status&P_FADIR))
        ret=(p1->info.status&P_FADIR)?-1:+1;
    else /* both records either dir or file names */
        ret=p_scmp(&p1->name[0],&p2->name[0]);
    if (self->varoot.key.desc)
        ret=(-ret); /* reverse result if required */
    return(ret);
    }
